# coding: utf-8
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base, Session

from ..setting import BANANA_DB_FILE

file = f'sqlite:///{BANANA_DB_FILE.as_posix()}'
engine = create_engine(file, echo=False, pool_size=10, max_overflow=20, pool_timeout=30, pool_recycle=1800)
DbBase = declarative_base()


def create_session() -> Session:
    return sessionmaker(bind=engine)()


def init_create_table() -> None:
    DbBase.metadata.create_all(bind=engine, checkfirst=True)

